/**
 * Copyright 2012 Alfredo "Rainbowbreeze" Morresi
 * 
 * This file is part of Eureka! project.
 * 
 * Eureka! is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * Eureka! is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with Eureka!. If not, see http://www.gnu.org/licenses/.
 */
package it.rainbowbreeze.eureka.data;

import it.rainbowbreeze.eureka.common.AppEnv;
import it.rainbowbreeze.eureka.util.TestHelper;
import android.content.Context;
import android.test.AndroidTestCase;
import android.test.MoreAsserts;

/**
 * @author Alfredo "Rainbowbreeze" Morresi
 *
 */
public class AppPreferenceDaoTest extends AndroidTestCase {
    // ------------------------------------------ Private Fields
    private AppPreferencesDao mAppPreferencesDao;

    // -------------------------------------------- Constructors

    // -------------------------------------- Setup and TearDown
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        
        Context context = getContext();
        assertNotNull("Context is null", context);
        TestHelper.init(context);
        mAppPreferencesDao = AppEnv.i(getContext()).getAppPreferencesDao();
    }
    
    // --------------------------------------------------- Tests
    public void testSaveData() {
        int[] expectedCategoryIds = new int[] {10, 43, 22};
        mAppPreferencesDao.setCategoryIds(expectedCategoryIds);
        mAppPreferencesDao.save();
        int[] expectedMeauserIds = new int[] {1, 2, 3};
        mAppPreferencesDao.setMeasureIds(expectedMeauserIds);
        mAppPreferencesDao.save();
        
        int[] actualCategoryIds = mAppPreferencesDao.getCategoryIds();
        MoreAsserts.assertEquals("Wrong categories", expectedCategoryIds, actualCategoryIds);
        int[] actualMeausureIds = mAppPreferencesDao.getMeasureIds();
        MoreAsserts.assertEquals("Wrong categories", expectedMeauserIds, actualMeausureIds);
        
        expectedCategoryIds = new int[] {};
        mAppPreferencesDao.setCategoryIds(expectedCategoryIds);
        mAppPreferencesDao.save();
        expectedMeauserIds = new int[] {5, 1, 6, 10, 354, 12};
        mAppPreferencesDao.setMeasureIds(expectedMeauserIds);
        mAppPreferencesDao.save();
        
        actualCategoryIds = mAppPreferencesDao.getCategoryIds();
        MoreAsserts.assertEquals("Wrong categories", expectedCategoryIds, actualCategoryIds);
        actualMeausureIds = mAppPreferencesDao.getMeasureIds();
        MoreAsserts.assertEquals("Wrong categories", expectedMeauserIds, actualMeausureIds);
    }

    // ----------------------------------------- Private Methods

    // ----------------------------------------- Private Classes
}
